home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / cisco / account.shar / getipacct.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1992-08-07  |  2KB  |  108 lines

  1. #!/bin/sh
  2. #
  3. # 1.2 90/04/12
  4.  
  5. umask 077
  6.  
  7. # remove tempfiles upon exit or interruption
  8. trap "rm -f /tmp/getipacct*.$$" 0 1 2
  9.  
  10. # create awk script to reduce and mark cisco output with date
  11. cat <<'EOF' >/tmp/getipacctawk.$$
  12. BEGIN {
  13.     months["Jan"] = 1;
  14.     months["Feb"] = 2;
  15.     months["Mar"] = 3;
  16.     months["Apr"] = 4;
  17.     months["May"] = 5;
  18.     months["Jun"] = 6;
  19.     months["Jul"] = 7;
  20.     months["Aug"] = 8;
  21.     months["Sep"] = 9;
  22.     months["Oct"] = 10;
  23.     months["Nov"] = 11;
  24.     months["Dec"] = 12;
  25. }
  26.  
  27. NR==1{
  28.     year = substr($NF, 3, 2);
  29.     month = months[$2];
  30.     day = $3;
  31.     split($4, time, ":");
  32.     hour = time[1];
  33.     minutes = time[2];
  34.     seconds = time[3] + 6;
  35.     
  36.     printf "\nSAMPLE %02d %02d %02d %02d %02d %02d\n\n", year, month, day, hour, minutes, seconds;
  37. }
  38. EOF
  39.  
  40.  
  41. # put date in a file
  42. #
  43. date | awk -f /tmp/getipacctawk.$$  >/tmp/getipacctlog.$$
  44.  
  45. cat <<'EOF' >/tmp/getipacctawk.$$
  46. / [0-9]*\.[0-9]*\.[0-9]*/ {
  47.     $4 = substr($4, 1, length($4)-1);
  48.     printf "%s %s %d %d\n", $1, $2, $3, $4;
  49. }
  50. EOF
  51.  
  52. # get cisco data, compress, sort and append to file
  53. #
  54. ETCDIR/ciscotalk <<'EOF'  | awk -f /tmp/getipacctawk.$$ \
  55. | sort -rn +3 >> /tmp/getipacctlog.$$
  56. NORMALPASSWORD
  57. term len 0
  58. show ip acc
  59. ena
  60. ENABLEPASSWORD
  61. clear ip acc
  62. clear ip acc
  63. quit
  64. EOF
  65.  
  66.  
  67. # append file to logfile
  68. #
  69. cat /tmp/getipacctlog.$$ >>LOGFILE
  70.  
  71. cat <<'EOF' >/tmp/getipacctawk.$$
  72. BEGIN {
  73.     cutpct = CUTPCT;
  74.     ntop = NTOP;
  75.     n = 0;
  76.     nby = 0;
  77.     npk = 0;
  78. }
  79.  
  80. /^SAMPLE/ {
  81.     print $0;
  82. }
  83.  
  84. /[0-9]*\.[0-9]*\./ {
  85.     if (n<ntop)
  86.     {
  87.         top[n] = $0;
  88.         bytes[n] = $4;
  89.     }
  90.     n++;
  91.     npk += $3;
  92.     nby += $4;
  93. }
  94.  
  95. END {
  96.     for (i=0; i<ntop; i++)
  97.     {
  98.         if (bytes[i] > nby*cutpct/100)
  99.             print top[i];
  100.     }
  101.     printf "SUM %d %d %d\n\n", n, npk, nby;
  102. }
  103. EOF
  104.  
  105. awk -f /tmp/getipacctawk.$$ </tmp/getipacctlog.$$ | ETCDIR/nameipacct >>COMPFILE
  106.  
  107.  
  108.